package com.zhou.org.dao;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhou.util.FileUtil;
import com.zhou.util.StringTool;
import com.zhou.framework.config.SystemConfig;
import com.zhou.org.model.OrgTree;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 
 * </p>
 *
 * @author lang.zhou
 * @since 2022-08-23
 */
@TableName("sys_user")
@Data
public class User implements Serializable {

    private static final long serialVersionUID=1L;

    /**
     * 用户id
     */
    @TableId(value = "user_id", type = IdType.AUTO)
    private Integer userId;

    /**
     * 用户名
     */
    private String username;

    /**
     * 姓名
     */
    private String realName;

    /**
     * 性别
     */
    private Integer sex;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 电话
     */
    private String phone;
    private String description;

    /**
     * 创建日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createDt;

    /**
     * 密码
     */
    private String password;

    /**
     * 盐
     */
    private String salt;

    /**
     * 微信code
     */
    private String wxCode;

    /**
     * 头像
     */
    private String relativeAvatar;

    /**
     * 是否锁定
     */
    private Integer locked;

    @TableField("orgid")
    private Integer orgId;

    /**
     * 行政上级用户id
     */
    @TableField("superior")
    private Integer superior;

    @TableField(exist = false)
    private List<OrgTree> parent;

    @TableField(exist = false)
    private String avatar;

    public void setRelativeAvatar(String relativeAvatar) {
        this.relativeAvatar = relativeAvatar;
        if(StringTool.isNotBlank(relativeAvatar)){
            if(!StringTool.isHttp(relativeAvatar)){
                avatar = FileUtil.formatFilePath(SystemConfig.getInstance().getRoot()) + relativeAvatar;
            }else{
                avatar = relativeAvatar;
            }
        }
    }


}
